User:Mkpoli/模組的坑

维基百科,自由的百科全书

剛剛開始編輯模組,我計畫將踩過的坑記錄在這裏

引用模板[编辑]

因爲模板有一定解析順序,如果模組的函數直接返回

{{Example|1=exemple|NamedArg1=hello|NamedArg2=world}}

這樣的wikitext,是不能得到執行的。這時候正確的方法應該使用API中的expandTemplate函數,具體地:

frame:expandTemplate{ title = "Example", args = {"exemple", NamedArg1 = "hello", NamedArg2 = "world"}}

調試[编辑]

有時用

error("foo" .. bar)

配合「预览使用本模板的页面」功能更方便

常看参考手册[编辑]

在这里:Lua reference manual